﻿using ServerManager.Models;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace ServerManager
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            Config config = GetConfig();
            var machineViewModel = new MachineViewModel();
            machineViewModel.ServerUrl = config.Server.Uri;
            DataContext = machineViewModel;
            InitializeComponent();
        }

        private static Config GetConfig()
        {
            var content = File.ReadAllText("./config.yaml");
            var deserializer = new DeserializerBuilder()
                .WithNamingConvention(UnderscoredNamingConvention.Instance)
                .Build();
            var config = deserializer.Deserialize<Config>(content);
            return config;
        }
    }
}